<template>
  <div style="height: 1.2rem">
    <div
        class="navbar-container"
        :class="{'box-shadow':!border,border:border}"
    >
      <div class="left-container" @click="onBackClick">
        <slot name="left">
          <img v-if="leftIcon" src="@/assets/vant-icon/arrow-left.png" alt="">
          <p> {{ leftText }} </p>
        </slot>
      </div>
      <div class="center-container">
        <slot name="center">
          <p :class="{bold:bold}">{{ title }}</p>
        </slot>
      </div>
      <div class="right-container" @click="onMoreClick">
        <slot name="right">
          <p v-if="!rightIcon">{{ rightText }}</p>
          <img v-if="rightIcon" src="@/assets/vant-icon/ellipsis.png" alt="">
        </slot>
      </div>
    </div>
  </div>

</template>

<script>
import './navbar.less'

export default {
  name: "navbar",
  props: {
    leftIcon: {
      type: Boolean,
      default: true
    },
    leftText: {
      type: String,
      default: '返回'
    },
    rightIcon: {
      type: Boolean,
      default: false
    },
    rightText: {
      type: String,
      default: ''
    },
    title: {
      type: String,
      default: '标题'
    },
    boxShadow: Boolean,
    border: {
      type: Boolean,
      default: false
    },
    bold: Boolean
  },
  methods: {
    onBackClick() {
      this.$router.back()
      // this.$emit('onBackClick')
    },
    onMoreClick() {
      this.$emit('onMoreClick')
    }
  }
}
</script>

<style lang="less" scoped>
.flex-center {
  display: flex;
  justify-content: center;
  align-items: center;
}

.navbar-container {
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 1.2rem;
  box-sizing: border-box;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  //margin-top: 1.4rem;
  background-color: #fff;
  z-index: 999;

  img {
    width: .4rem;
    height: .4rem;
    margin-right: .1rem;
  }

  .left-container {
    width: 2rem;
    text-align: center;
    font-size: .4rem;
    .flex-center();
  }

  .center-container {
    flex: 1;
    text-align: center;
    font-size: .5rem;
  }

  .right-container {
    width: 2rem;
    text-align: center;
    font-size: .4rem;
    .flex-center();

    img {
      margin-right: 0;
    }
  }
}

.box-shadow {
  box-shadow: 0 .1rem .1rem #eee;
}

.border {
  border-bottom: 1px solid #eeeeee;
}

.bold {
  font-weight: bold;
}
</style>